package com.lipl.base.javase.reflect;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * @Auther: 15541
 * @Date: 2021/4/30 17:46
 * @Description:
 */
public class ReflectTest {


    public static void main(String[] args) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException, InstantiationException, ClassNotFoundException {
        //Class userClass = User.class;

        Class<?> userClass = Class.forName("com.lipl.base.javase.reflect.User");

        Object userInstance = userClass.newInstance();
        User user = new User();
//        Class<?> paramTypes[] = null;
//        paramTypes[0] = Integer.class;
//        paramTypes[1] = Integer.class;
        Integer[] integers = new Integer[]{1,2};
        //Method method = userInstance.getClass().getMethod("getUser",userClass);
        Method method1 = userInstance.getClass().getMethod("add",Integer[].class);


        System.out.println(method1.invoke(user,new Object[]{integers}));
    }

}

